package exception;

import java.io.FileNotFoundException;

public class Student {
    private  int age ;

    public Student() {
    }

    public Student(int age) {
        this.age = age;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) throws IllegalAgeException {
        if(age<0||age>120)
        {
            throw new IllegalAgeException("年龄不合法");//抛出一个检查异给调用者,需要throws
           // throw new RuntimeException();//抛出一个非检查异常,年龄不在范围内则报错,不需要throws
        }
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "age=" + age +
                '}';
    }
}
